////////////////////////////////////////////////////////////////////////////////


*This do-file creates tables 1 and 6 (summary stats tables) in the main text. Tables 2-5 and 7, which summarize the regression analyses, are created in the next do-file.


////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////

*Table 1

////////////////////////////////////////////////////////////////////////////////

*GSS

cd "$usdata"

use "clean/gss_clean.dta", clear
	gen married=1 if marital==1
	replace married=0 if marital>1&marital<.
svyset _n [pw=wtssall]

qui eststo gss_pre: svy: mean age male married nonwhite immigrant ///
uni semp parttime union if insample==1&year<2008
estat sd
estadd matrix r(sd)

qui eststo gss_post: svy: mean age male married nonwhite immigrant ///
uni semp parttime union if insample==1&year>=2008
estat sd
estadd matrix r(sd)

*HRS

cd "$usdata"

use "clean/hrs_clean.dta", clear
	gen married=1 if marital==1
	replace married=0 if marital>1&marital<.
svyset _n [pw=wtresp]

qui eststo hrs_pre: svy: mean age male married nonwhite immigrant ///
uni parttime union if insample==1&year<2008
estat sd
estadd matrix r(sd)

qui eststo hrs_post: svy: mean age male married nonwhite immigrant ///
uni parttime union if insample==1&year>=2008
estat sd
estadd matrix r(sd)

*BHPS

cd "$ukdata"

use "clean/uk_linear_reverse.dta", clear
	gen married=1 if marital==1
	replace married=0 if marital>1&marital<.
svyset _n [pw=relative_xw]
	
qui eststo bhps_pre: svy: mean age male married nonwhite immigrant ///
uni temp semp semp_boss parttime union jobtenure if insample==1&year<2008
estat sd
estadd matrix r(sd)

qui eststo bhps_post: svy: mean age male married nonwhite immigrant ///
uni temp parttime union jobtenure if insample==1&year>=2008
estat sd
estadd matrix r(sd)

*SOEP

cd "$germanydata"

use "clean/soep_clean.dta", clear	
	gen married=1 if marital==1|marital==6
	replace married=0 if marital>1&marital<.
	replace jobtenure=. if jobtenure<0

svyset _n [pw=xw]
	
qui eststo soep_pre: svy: mean age male married immigrant uni temp marginal semp parttime jobtenure if insample==1&year<2008
estat sd
estadd matrix r(sd)

qui eststo soep_post: svy: mean age male married immigrant uni temp marginal semp parttime jobtenure if insample==1&year>=2008
estat sd
estadd matrix r(sd)
	
*Make table

cd "$tables"

esttab gss_pre gss_post hrs_pre hrs_post bhps_pre bhps_post soep_pre soep_post using "summary_stats_all.tex", replace varwidth(0) cells(b(fmt(%9.3g)) sd(fmt(%9.3g) par(( )))) order(age male married nonwhite immigrant uni parttime union temp semp semp_boss marginal jobtenure) collabels("") booktabs mgroups ("GSS" "HRS" "BHPS" "SOEP", pattern(1 0 1 0 1 0 1 0) span prefix(\multicolumn{@span}{c}{) suffix(})) mlabels("\specialcell{pre-\\ 2008}" "\specialcell{post-\\ 2008}" "\specialcell{pre-\\ 2008}" "\specialcell{post-\\ 2008}" "\specialcell{pre-\\ 2008}" "\specialcell{post-\\ 2008}" "\specialcell{pre-\\ 2008}" "\specialcell{post-\\ 2008}") nonumbers coeflabels(age "Age" male "Male" married "Married" nonwhite "Non-white" immigrant "Immigrant" uni "Tertiary degree" semp "Self-employed without employees$^a$" semp_boss "Self-employed with employees" parttime "Part-time worker" union "Union member" temp "Temporary worker" marginal "Marginally employed" jobtenure "Job tenure") postfoot("\tabnotes{9}{a: This row displays the mean for all self-employed workers for the US and Germany.}") gaps title("Descriptive statistics, pre- and post-2008") width(\hsize)

////////////////////////////////////////////////////////////////////////////////

*Table 6

////////////////////////////////////////////////////////////////////////////////

cd "$europedata"

use "clean/ewcs_clean.dta", clear	
	rename countid country
	la var country "Country"
	la var year "Year"

	collapse (mean) insecure if insample [pweight=xw], by(year country)
	replace insecure=insecure*100
	
	reshape wide insecure, i(year) j(country)
	set obs 4
	replace year=9999 in 4
	sort year
	forval i=1/36 {
		replace insecure`i'=insecure`i'[_n-1]-insecure`i'[_n-3] if year==9999
	}
	
	la var insecure1 "Belgium"
	la var insecure2 "Bulgaria"
	la var insecure3 "Czech Republic"
	la var insecure4 "Denmark"
	la var insecure5 "Germany"
	la var insecure6 "Estonia"
	la var insecure7 "Greece"
	la var insecure8 "Spain"
	la var insecure9 "France"
	la var insecure10 "Ireland"
	la var insecure11 "Italy"
	la var insecure12 "Cyprus"
	la var insecure13 "Latvia"
	la var insecure14 "Lithuania"
	la var insecure15 "Luxembourg"
	la var insecure16 "Hungary"
	la var insecure17 "Malta"
	la var insecure18 "Netherlands"
	la var insecure19 "Austria"
	la var insecure20 "Poland"
	la var insecure21 "Portugal"
	la var insecure22 "Romania"
	la var insecure23 "Slovenia"
	la var insecure24 "Slovakia"
	la var insecure25 "Finland"
	la var insecure26 "Sweden"
	la var insecure27 "United Kingdom"
	la var insecure28 "Croatia"
	la var insecure29 "North Macedonia"
	la var insecure30 "Turkey"
	la var insecure31 "Norway"
	la var insecure32 "Albania"
	la var insecure33 "Kosovo"
	la var insecure34 "Montenegro"
	la var insecure35 "Switzerland"
	la var insecure36 "Serbia"
	
	estimates clear
	
	foreach i in 2005 2010 2015 9999 {
		estpost sum insecure* if year==`i'
		eststo y_`i'
	}

cd "$tables"
	
esttab y_2005 y_2010 y_2015 y_9999 using "ewcs_security.tex", cell(mean(fmt(%8.1f))) collabels("" "" "") mlabels("2005" "2010" "2015" "p.p. change, 2005-2015") title("Job insecurity in Europe") postfoot("\tabnotes{5}{Data from the European Working Conditions Survey Table shows proportion of workforce that feels insecure.}") nonumbers label noobs replace booktab width(\hsize)
